using System;
using System.Globalization;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Data.Converters;
using Avalonia.VisualTree;

namespace SocketTool.Converters
{
    /// <summary>
    /// treeView 数据缩进转换器
    /// </summary>
    public class TreeViewIdentationConverter : IValueConverter
    {
        public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
        {
            double colunwidth = 20;
            double left = 0.0;


            var element = value as TreeViewItem;
            while (element.GetType() != typeof(TreeView))
            {
                var visual = element.GetVisualParent();
                if (visual.GetType() == typeof(TreeViewItem))
                    left += colunwidth;
            }
            return new Thickness(left, 0, 0, 0);
        }

        public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}